#pragma once

#include "DurationConstraint.h"

#include "DurationInterval.h"

namespace uml {

DurationConstraint::DurationConstraint(const QString& umlType)
    : IntervalConstraint(umlType) {}

void DurationConstraint::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    IntervalConstraint::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(firstEvents_, "firstEvents", json, errorList);
    specification_ = JsonSerializable::create<DurationInterval>(json.value("specification"), errorList);

}

void DurationConstraint::toJson(QJsonObject& json) {
    IntervalConstraint::toJson(json);
    JsonSerializable::toJsonArray(firstEvents_, "firstEvents", json);
    if (specification_) {
        QJsonObject specification_json;
        specification_->toJson(specification_json);
        json.insert("specification", specification_json);
    }
}

/// <summary>
/// firstEvents getter
/// The value of firstEvent[i] is related to constrainedElement[i] (where i is 1 or
/// 2). If firstEvent[i] is true, then the corresponding observation event is the
/// first time instant the execution enters constrainedElement[i]. If firstEvent[i]
/// is false, then the corresponding observation event is the last time instant the
/// execution is within constrainedElement[i].
/// </summary>
vector<bool>& DurationConstraint::firstEvents() {
    return firstEvents_;
}

/// <summary>
/// specification getter
/// The DurationInterval constraining the duration.
/// </summary>
shared_ptr<DurationInterval> DurationConstraint::specification() const {
    return specification_;
}

/// <summary>
/// specification setter
/// The DurationInterval constraining the duration.
/// </summary>
void DurationConstraint::setSpecification(shared_ptr<DurationInterval> value) {
    specification_ = value;
}

} // namespace uml
